package cn.doitedu.visualiz.platform.util;

public class SqlHelper {

    StringBuilder selectSb = new StringBuilder("select ");
    StringBuilder fromSb = new StringBuilder(" from ");
    StringBuilder whereSb = new StringBuilder(" where ");

    public SqlHelper select(String expr) {
        selectSb.append(expr).append(",");
        return this;
    }

    public SqlHelper from(String table) {
        fromSb.append(table).append(",");

        return this;
    }


    public SqlHelper where(String expr) {
        whereSb.append(expr);

        return this;
    }


    public String getSql() {

        return selectSb.toString().substring(0, selectSb.length() - 1) + "\n"
                +
                fromSb.toString().substring(0, fromSb.length() - 1)+ "\n"
                +
                whereSb.toString()+ "\n";

    }


    public static void main(String[] args) {


        SqlHelper sqlHelper = new SqlHelper();
        String sql = sqlHelper.select("id").select("name").from("t_stu").where("sex=male").getSql();
        System.out.println(sql);


    }


}
